String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
//验证提交
function checkSubmit()
{
 var  email =$("#email");
  if(email.val().trim().length==0)
  {
     alert("请输入邮箱!");
     email.focus();
     return;
  }
  var  emailRegex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
  if(!emailRegex.test(email.val().trim()))
  {
     alert("输入邮箱格式错误!");
     email.focus();
     return;
  }
  $.ajax({
    url:'../../member/checkEmail.action?email='+email.val().trim(),
    type:'post',
    success:function (msg)
    {
         var a=eval('('+msg+')');
         if(a['result'])
         {
            alert('输入的邮箱已经被注册了!');
         }else{
var  password = $("#password");
  if(password.val().trim().length==0)
  {
     alert("请输入密码!");
     password.focus();
     return;
  }
  var  newpass = $("#newpass");
  if(newpass.val().trim().length==0)
  {
     alert("请再次输入密码!");
     newpass.focus();
     return;
  }
  if(!(password.val().trim()==newpass.val().trim()))
  {
     alert("输入的密码，两次密码不一致!");
     newpass.focus();
     return;
  }
   var  realName = $("#realName");
  if(realName.val().trim().length==0)
  {
     alert("请输入真实姓名!");
     realName.focus();
     return;
  }
  var  realNameRegex =  /([0-9_-])+/;
  if(realNameRegex.test(realName.val().trim()))
  {
     alert("真实姓名只能输入中文或字母");
     realName.focus();
     return;
  }
  if(realName.val().trim().length<2)
  {
     alert("请输入字母至少4位，汉字至少两个字");
     realName.focus();
     return;
  }
  var  phone = $("#phone");
  if(phone.val().trim().length==0)
  {
     alert("请输入手机号码!");
     phone.focus();
     return;
  }
  var phoneRegex = /1([0-9]){10}/
  if(!phoneRegex.test(phone.val().trim()))
  {
       alert("手机号码输入格式错误!");
       phone.focus();
       return;
  }
   var  checkcode = $("#checkcode");
  if(checkcode.val().trim().length==0)
  {
     alert("请输入身份证!");
     checkcode.focus();
     return;
  }
  var checkcodeRegex = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
  if(!checkcodeRegex.test(checkcode.val().trim()))
  {
       alert("身份证输入格式错误!");
       checkcode.focus();
       return;
  }
  var  code = $("#code");
  if(code.val().trim().length==0)
  {
     alert("请输入验证码!");
     code.focus();
     return;
  }
  $.ajax({
     type:'post',
     url:'../../member/checkCode.action?code='+code.val(),
     success:function(msg)
     {
         var a=eval('('+msg+')');
         if(!a['result'])
         {
            alert('验证码输入错误!')
         }else{
              
		       var  read =$("#read");
		       if(!read.attr("checked"))
		       {
		          alert("请先阅读并同意 网站条款!");
		          return;
		       }
		        $.ajax({
			         data:'tsSysuser.password='+password.val().trim()+"&tsSysuser.category=2&"+
	                   "tsSysuser.lock=2&tmMember.realName="+realName.val().trim()+"&tmMember.idcard="+checkcode.val().trim()
	                   +"&tmMember.phone="+phone.val().trim()+"&tmMember.email="+email.val().trim()
	                   +"&tmMember.districtId="+$("#city").val(),
				      url:'../../member/registerMember.action',
				      type:'post',
				      success:function(msg){
			            alert("b=="+msg);
	          	}
	          });
            
         }
        
     }
  
  });
         
         }
    }
  
  
  
  });
 
}
$(document).ready(function()
{
     var proce = $("#proce");
     $.ajax({
        url:'../../district/loadDistrictSelect.action',
        type:'post',
        success:function(msg){
            var obj =eval('('+msg+')');
            var  thtml="";
            $.each(obj,function(i,n){
                
                 var b=n["id"];
                 var c=n["name"];
                thtml+= '<option value='+b+'>'+c+'</option>';
                
            });
             proce.html(thtml); 
             loadCity();
        },
       params:{pid:'-1'}
     });
}
);
function  loadCity()
{
     var proce = $("#proce");
     var s = proce.val();
     var city = $("#city");
      $.ajax({
        url:'../../district/loadDistrictSelect.action?pid='+s,
        type:'post',
        success:function(msg){
            var obj =eval('('+msg+')');
            var m="";
            $.each(obj,function(i,n){
                
                 var b=n["id"];
                 var c=n["name"];
                m+= '<option value='+b+'>'+c+'</option>';
                
            });
             city.html(m); 
        }
     });
}

function  loadCode()
{
   var  img =$("#img");
   img.attr("src","yanzhengma.jsp?date="+new Date());
}
//身份证校验
var yyyy;
var mm;
var dd;
var birthday;
var sex;
var birthmonth;

function getYear() {
    return yyyy;
}
function getMonth() {
    return mm;
}
function getDate() {
    return dd;
}
function getBirthday() {
    return birthday;
}
function getSex() {
    return sex;
}
function getBirthMonth() {
    return  birthmonth;
}
function getAge() {
    var mm = getMonth();
    if (mm < 10)
        mm = mm.substring(1, 2);
    return Math.floor((parseInt(_getYear()) * 12 + parseInt(_getMonth()) - parseInt(getYear()) * 12 - parseInt(mm)) / 12);
}

//校验身份证号码
function CheckCardValue(idCard) {
    var id = idCard;
    var id_length = id.length;
    if (id_length == 0) {
        alert("请输入身份证号码!");
        return false;
    }
    if (id_length != 15 && id_length != 18) {
        alert("身份证号长度应为15位或18位！");
        return false;
    }
    if (id_length == 15) {
        yyyy = "19" + id.substring(6, 8);
        mm = id.substring(8, 10);
        dd = id.substring(10, 12);
         
        if (mm > 12 || mm <= 0) {
            alert("输入身份证号,月份非法！");
            return false;
        }
        if (dd > 31 || dd <= 0) {
            alert("输入身份证号,日期非法！");
            return false;
        }
        birthday = yyyy + "-" + mm + "-" + dd;
        birthmonth = yyyy + mm;
        if ("13579".indexOf(id.substring(14, 15)) != -1) {
            sex = "1";
        } else {
            sex = "2";
        }
    }
    else if (id_length == 18) {
        if (id.indexOf("X") > 0 && id.indexOf("X") != 17 || id.indexOf("x") > 0 && id.indexOf("x") != 17) {
            alert("身份证中\"X\"输入位置不正确！");
            return false;
        }
        yyyy = id.substring(6, 10);
        if (yyyy > 2200 || yyyy < 1900) {
            alert("输入身份证号,年度非法！");
            return false;
        }
        mm = id.substring(10, 12);
        if (mm > 12 || mm <= 0) {
            alert("输入身份证号,月份非法！");
            return false;
        }
        dd = id.substring(12, 14);
        if (dd > 31 || dd <= 0) {
            alert("输入身份证号,日期非法！");
            return false;
        }
        if (id.charAt(17) == "x" || id.charAt(17) == "X")
        {
            if ("x" != GetVerifyBit(id) && "X" != GetVerifyBit(id)) {
                alert("身份证校验错误！");
                return false;
            }
        } else {
            if (id.charAt(17) != GetVerifyBit(id)) {
                alert("身份证校验错误！");
                return false;
            }
        }
        birthday = id.substring(6, 10) + "-" + id.substring(10, 12) + "-" + id.substring(12, 14);
        birthmonth = id.substring(6, 10) + id.substring(10, 12);
        if ("13579".indexOf(id.substring(16, 17)) > -1) {
            sex = "1";
        } else {
            sex = "2";
        }
    }
    return true;
}
//15位转18位中,计算校验位即最后一位
function GetVerifyBit(id) {
    var result;
    var nNum = eval(id.charAt(0) * 7 + id.charAt(1) * 9 + id.charAt(2) * 10 + id.charAt(3) * 5 + id.charAt(4) * 8 + id.charAt(5) * 4 + id.charAt(6) * 2 + id.charAt(7) * 1 + id.charAt(8) * 6 + id.charAt(9) * 3 + id.charAt(10) * 7 + id.charAt(11) * 9 + id.charAt(12) * 10 + id.charAt(13) * 5 + id.charAt(14) * 8 + id.charAt(15) * 4 + id.charAt(16) * 2);
    nNum = nNum % 11;
    switch (nNum) {
        case 0 :
            result = "1";
            break;
        case 1 :
            result = "0";
            break;
        case 2 :
            result = "X";
            break;
        case 3 :
            result = "9";
            break;
        case 4 :
            result = "8";
            break;
        case 5 :
            result = "7";
            break;
        case 6 :
            result = "6";
            break;
        case 7 :
            result = "5";
            break;
        case 8 :
            result = "4";
            break;
        case 9 :
            result = "3";
            break;
        case 10 :
            result = "2";
            break;
    }
    //document.write(result);
    return result;
}